package com.globant.profy.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import javax.persistence.Table;



@Entity
@Table(name = "users")

public class User {

private String name;
private String company;
private String jobTitle;
private String email;
private int id;
private int enabled;
private String experience;

private String password;

private List<Languages> languages;

private Permisos permission;

	public User() {
	}

	public User(String email) {
		this.email = email;
	}

	public User(String email, Permisos permission) {
		this.email = email;
		this.permission = permission;
	}

	public User(String name, String company, String jobTitle, String email,
			String experience, List<Languages> languag) {
		this.name = name;
		this.company = company;
		this.jobTitle = jobTitle;
		this.email = email;
		this.experience = experience;
		this.languages = languag;

	}

public String getPassword() {
	return password;
}
public void setPassword(String password) {
	this.password = password;
}
public int getEnabled() {
	return enabled;
}

public void setEnabled(int enabled) {
	this.enabled = enabled;
}

public void setPermission(Permisos permission) {
	this.permission = permission;
}

@OneToOne(fetch=FetchType.EAGER,cascade = CascadeType.ALL)
public Permisos getPermission() {
	return permission;
}

@ManyToMany(cascade = CascadeType.ALL)
public List<Languages> getLanguages() {
	return languages;
}

public void setLanguages(List<Languages> languages) {
	this.languages = languages;
}


@Column(name = "user_name")
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name = "user_company")
public String getCompany() {
return company;
}

public void setCompany(String company) {
this.company = company;
}

@Column(name = "user_jobTitle")
public String getJobTitle() {
return jobTitle;
}

public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}

@Column(name = "user_email")
public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Id
@GeneratedValue
@Column(name = "user_id")
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Column(name = "user_experience")
public String getExperience() {
return experience;
}

public void setExperience(String experience) {
this.experience = experience;
}


@Override
public String toString() {
return "User [name=" + name + "]";
}

@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	User other = (User) obj;
	if (company == null) {
		if (other.company != null)
			return false;
	} else if (!company.equals(other.company))
		return false;
	if (email == null) {
		if (other.email != null)
			return false;
	} else if (!email.equals(other.email))
		return false;
	if (enabled != other.enabled)
		return false;
	if (experience == null) {
		if (other.experience != null)
			return false;
	} else if (!experience.equals(other.experience))
		return false;
	if (id != other.id)
		return false;
	if (jobTitle == null) {
		if (other.jobTitle != null)
			return false;
	} else if (!jobTitle.equals(other.jobTitle))
		return false;
	if (name == null) {
		if (other.name != null)
			return false;
	} else if (!name.equals(other.name))
		return false;
	if (password == null) {
		if (other.password != null)
			return false;
	} else if (!password.equals(other.password))
		return false;
	if (permission == null) {
		if (other.permission != null)
			return false;
	} else if (!permission.equals(other.permission))
		return false;
	return true;
}
@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((company == null) ? 0 : company.hashCode());
	result = prime * result + ((email == null) ? 0 : email.hashCode());
	result = prime * result + enabled;
	result = prime * result
			+ ((experience == null) ? 0 : experience.hashCode());
	result = prime * result + id;
	result = prime * result
			+ ((jobTitle == null) ? 0 : jobTitle.hashCode());
	result = prime * result + ((name == null) ? 0 : name.hashCode());
	result = prime * result
			+ ((password == null) ? 0 : password.hashCode());
	result = prime * result
			+ ((permission == null) ? 0 : permission.hashCode());
	return result;
}

}
